package exteditapp;

import java.io.File;

import exteditapp.state.IState;

/**
 * File object. With it's own states and other parameters.
 * 
 * This class "extends" File class for application needs - such as current state, download/upload url,
 * custom modification date.
 * @author Arturas Smorgun, arturas@smorgun.lt
 * @version 2009.04.22
 */
public class FileDefault {
	
	/**
	 * current file state
	 */
	protected IState currentState;
	
	/**
	 * main program module
	 */
	protected IModuleApplet module;
	
	/**
	 * url address of file
	 */
	protected String name;
	
	/**
	 * url, from which file was downloaded
	 */
	protected String downloadURL;

	/**
	 * url, to which file might be uploaded
	 */
	protected String uploadURL;

	/**
	 * file as object
	 */
	protected File fileAsObject;

	/**
	 * Time of last file modification. Used on idle to determine if file was modified while stand-by
	 */
	protected long lastModified;
	
	/**
	 * Class constructor, which sets this file name
	 */
	public FileDefault(String name){
		this.setName(name);
	}

	/**
	 * Return currentState
	 * @return
	 */	
	public IState getCurrentState(){
		return this.currentState;
	}

	/**
	 * Set the value of currentState.
	 * @param mycurrentState 
	 */
	public void setCurrentState(IState mycurrentState){
		if(!mycurrentState.equals(this.currentState)){
			this.currentState = mycurrentState;
			System.out.println("NEW STATE: "+mycurrentState.toString()+" "+System.currentTimeMillis());
		}
	}

	/**
	 * Return module
	 * @return IModule
	 */	
	public IModuleApplet getModule(){
		return this.module;
	}	

	/**
	 * Set the value of module.
	 * @param mymodule 
	 */
	public void setModule(IModuleApplet mymodule){
		this.module = mymodule;
	}	

	/**
	 * Return name
	 * @return 
	 */	
	public String getName(){
		return this.name;
	}	

	/**
	 * Set the value of name.
	 * @param myurl 
	 */
	public void setName(String myName){
		this.name = myName;
	}	

	/**
	 * Return upload url
	 * @return 
	 */	
	public String getDownloadURL(){
		return this.downloadURL;
	}
	
	/**
	 * Set download url
	 * @param myDownloadURL
	 */
	public void setDownloadURL(String myDownloadURL){
		this.downloadURL = myDownloadURL;
	}

	/**
	 * Return upload url
	 * @return 
	 */	
	public String getUploadURL(){
		return this.uploadURL;
	}
	
	/**
	 * Set upload url
	 * @param myUploadURL 
	 */
	public void setUploadURL(String myUploadURL){
		this.uploadURL = myUploadURL;
	}	

	/**
	 * Return file as File objectas object
	 * @return 
	 */	
	public File getFileAsObject(){
		return this.fileAsObject;
	}	

	/**
	 * Set file parameters from File object
	 * @param myFileAsObject 
	 */
	public void setFileAsObject(File myFileAsObject){
		this.fileAsObject = myFileAsObject;
		
		this.lastModified = myFileAsObject.lastModified();
	}
	
	/**
	 * Return time of last modification
	 * @return
	 */
	public long getLastModified(){
		return this.lastModified;
	}
	
	/**
	 * Update (set) time of last modification
	 * @param lastModified
	 */
	public void setLastModified(long lastModified){
		this.lastModified = lastModified;
	}

}
